package net.chrisrichardson.cloudtools.maven.plugins;

import net.chrisrichardson.ec2deployer.cluster.ClusterManager;
import net.chrisrichardson.ec2deployer.cluster.ClusterSpec;
import net.chrisrichardson.ec2deployer.cluster.SimpleCluster;

/**
 * Turn on EBS for a cluster that is using instance storage
 * 
 * @goal enableebs
 * @author cer
 * 
 */
public class EnableEbsMojo extends AbstractClusterMojo {

  /**
   * ebs device 
   * 
   * @parameter expression="${cloudtools.ebs.device}"
   * @required
   */
  protected String ebsDevice;

  /**
   * ebs volume size
   * 
   * @parameter expression="${cloudtools.ebs.volume.size}
   * @required
   */
  protected Integer ebsVolumeSize;

  @Override
  protected void executeWithCluster(ClusterManager manager, SimpleCluster cluster) {
    ClusterSpec clusterSpec = cluster.getSpec();
    clusterSpec.withNewEbsVolume(ebsVolumeSize, ebsDevice);
    cluster.getClusterInstance().getDatabaseTier().getDatabaseServer().configureDatabase();
    manager.saveCluster(getClusterName(), cluster);
  }

}
